# curl -H 'Host: www.cwl.gov.cn' -H
# 'Accept: application/json, text/javascript, */*; q=0.01'
# 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36'
# 'X-Requested-With: XMLHttpRequest'
# 'Referer: http://www.cwl.gov.cn/ygkj/wqkjgg/ssq/'
# 'Accept-Language: en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7'
# 'Cookie: HMF_CI=97b158385951ebcc3b5da7317b08cd2515fa518cc9ecf518c15ccc67f4a08a669338e6c4462b4635cb0f1b59435f61ce04961503efd36a47447be942ed17845a77; 21_vq=96'
# --compressed 'http://www.cwl.gov.cn/cwl_admin/front/cwlkj/search/kjxx/findDrawNotice?name=ssq&issueCount=30&issueStart=&issueEnd=&dayStart=&dayEnd='

import json
from collections import Counter
import datetime

import requests

if __name__ == '__main__':
    header = {
        'Host': 'www.cwl.gov.cn', 'Accept': 'application/json, text/javascript, */*; q=0.01',
        'Authorization': 'bearereyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxMjMzODY1NiIsImlhdCI6MTY2NjE1Nzc4NywiZXhwIjoxNjY4NzQ5Nzg3LCJuYmYiOjE2NjYxNTc3ODd9.v8tIWOFxeOprAcYqypCEA-6s5lkIPATpgQudWJgjpeA',
        'Accept-Language': 'en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7',
        'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36',
        'Referer': 'http://www.cwl.gov.cn/ygkj/wqkjgg/ssq/',
        'X-Requested-With': 'XMLHttpRequest',
        'Cookie': 'HMF_CI=97b158385951ebcc3b5da7317b08cd2515fa518cc9ecf518c15ccc67f4a08a669338e6c4462b4635cb0f1b59435f61ce04961503efd36a47447be942ed17845a77; 21_vq=96'

    }

    today = datetime.datetime.now().strftime("%Y-%m-%d")
    response = requests.get(
        f'http://www.cwl.gov.cn/cwl_admin/front/cwlkj/search/kjxx/findDrawNotice?name=ssq&issueCount=&issueStart=&issueEnd=&dayStart=2024-12-24&dayEnd={today}&pageNo=1&pageSize=3000&week=&systemType=PC',
        headers=header)

    red = ['01', '04', '05', '12', '14', '30']
    blue = '07'

    today_reds = []
    today_blues = []
    for today in json.loads(response.text)['result']:
        # today = json.loads(response.text)['result'][0]

        for item in today['red'].split(','):
            today_reds.append(item)
        today_blues.append(today['blue'])
        # print(today['code'], today['date'], today['red'], today['blue'])

        # win = today['red'].split(',')
        #
        # redNum = 0
        # blueNum = 0
        # for ball in red:
        #     if ball in win:
        #         redNum = redNum + 1
        #
        # if blue in today['blue']:
        #     blueNum = 1
        #
        # if redNum > 3 or blue in today['blue']:
        #     print(f'win！red:{redNum}, blue:{blueNum}')
        # else:
        #     print(f'lose！red:{redNum}, blue:{blueNum}')
    counter = Counter(today_reds)
    top_6 = counter.most_common(6)
    # top_6 = counter.most_common()[:-7:-1]
    print("红：")
    buy_reds = []
    for num, count in top_6:
        print("{} 出现了 {} 次".format(num, count))
        buy_reds.append(num)
        
    print(list(map(str, sorted([int(i) for i in buy_reds]))))

    counter2 = Counter(today_blues)
    top_1 = counter2.most_common(1)
    print("蓝：")
    for num, count in top_1:
        print("{} 出现了 {} 次".format(num, count))
        print(num)
